<template>
  <el-card class="box-card">
    <el-form :inline="true" :disabled="isDisabled" :model="formInline" class="demo-form-inline">
      <el-form-item label="一级分类">
        <el-select v-model="category1Id" placeholder="请选择">
          <el-option v-for="c1 in category.category1List" :label="c1.name" :key="c1.id" :value="c1.id" />

        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select v-model="category2Id" placeholder="请选择">
          <el-option v-for="c2 in category.category2List" :label="c2.name" :value="c2.id" :key="c2.id"/>
         
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select v-model="category3Id" placeholder="请选择">
          <el-option  v-for="c3 in category.category3List" :label="c3.name" :value="c3.id" :key="c3.id"/>
          
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>
  
<script lang="ts">
export default {
  name: 'CategorySelector'
}
</script>
<script lang="ts" setup>
import { reactive, onMounted, computed } from 'vue'
// import {reqCategorySelector1List}from '@/api/product/categorySelector'
import { useCategoryListStore } from '@/stores/categoryList'
defineProps(['isDisabled'])
const category = useCategoryListStore()
//1.挂载阶段获取一级分类数据
onMounted(async () => {
  // const result = await reqCategorySelector1List()
  // // console.log(result)
  category.getCategory1ListData()
})

//2.使用计算属性发送请求获取二级分类数据
const category1Id = computed({
  get() {
    return category.category1Id as number
   },
  set(val) {
    //  console.log('aa',val)
    category.getCategory2ListData(val)
   }
})

// 使用计算属性发送请求获取三级分类数据
const category2Id = computed({
  get(){
    return category.category2Id as number
  },
  set(val){
    category.getCategory3ListData(val)
  }
})

const category3Id = computed({
  get(){
    return category.category3Id as number
  },
  set(val){
    category.setCategory3Id(val)
  }
})

const formInline = reactive({
  user: '',
  region: '',
})

const onSubmit = () => {
  console.log('submit!')
}
</script>
  
  
<style></style>